package org.istone.study.mybatis.service.impl;

import java.util.Date;
import java.util.List;

import org.istone.study.mybatis.core.MyBatis;
import org.istone.study.mybatis.model.Student;
import org.istone.study.mybatis.service.StudentDataService;

/**
 * @author Administrator
 * @date Jan 17, 2012 2:59:49 PM
 */
public class StudentDataServiceImpl implements StudentDataService {

    /**
     * @param identifier
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#getStudentById(java.lang.String)
     */
    public Student getStudentById(String identifier) {
	return (Student) MyBatis.getSqlSession().selectOne("getStudentById",
		identifier);
    }

    /**
     * @param student
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#addStudent(org.istone.study.mybatis.model.Student)
     */
    public boolean addStudent(Student student) {
	return MyBatis.getSqlSession().insert("addStudent", student) == 1 ? true
		: false;
    }

    /**
     * @param students
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#addStudents(java.util.List)
     */
    public boolean addStudents(List<Student> students) {
	return MyBatis.getSqlSession().insert("addStudents", students) == 1 ? true
		: false;
    }

    /**
     * @param student
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#updateStudentInfo(org.istone.study.mybatis.model.Student)
     */
    public boolean updateStudentInfo(Student student) {
	return MyBatis.getSqlSession().update("updateStudentInfo", student) == 1 ? true
		: false;
    }

    /**
     * @param students
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#updateStudentsInfo(java.util.List)
     */
    public boolean updateStudentsInfo(List<Student> students) {
	return MyBatis.getSqlSession().update("updateStudentsInfo", students) == 1 ? true
		: false;
    }

    /**
     * @param student
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#deleteStudent(org.istone.study.mybatis.model.Student)
     */
    public boolean deleteStudent(Student student) {
	return MyBatis.getSqlSession().delete("deleteStudent", student) == 1 ? true
		: false;
    }

    /**
     * @param students
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#deleteStudents(java.util.List)
     */
    public boolean deleteStudents(List<Student> students) {
	return MyBatis.getSqlSession().delete("deleteStudents", students) == 1 ? true
		: false;
    }

    /**
     * @param firstName
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#queryStudentsByFirstName(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    public List<Student> queryStudentsByFirstName(String firstName) {
	return MyBatis.getSqlSession().selectList("queryStudentsByFirstName",
		firstName);
    }

    /**
     * @param lastName
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#queryStudentsByLastName(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    public List<Student> queryStudentsByLastName(String lastName) {
	return MyBatis.getSqlSession().selectList("queryStudentsByLastName",
		lastName);
    }

    /**
     * @param birthday
     * @return
     * @see org.istone.study.mybatis.service.StudentDataService#queryStudentsByBirthday(java.util.Date)
     */
    @SuppressWarnings("unchecked")
    public List<Student> queryStudentsByBirthday(Date birthday) {
	return MyBatis.getSqlSession().selectList("queryStudentsByBirthday",
		birthday);
    }

}
